<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2021/9/1
  Time: 14:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="adminMenu.jsp" %>
<!--/sidebar-->
<div class="main-wrap">

    <div class="crumb-wrap">
        <div class="crumb-list"><i class="icon-font"></i><a href="index.html">首页</a><span
                class="crumb-step">&gt;</span><span class="crumb-name">用户管理</span></div>
    </div>
    <div class="search-wrap">
        <div class="search-content">
            <form action="adminDoUserGet" method="get">
                <table class="search-tab">
                    <tr>
                        <%--<th width="120">选择分类:</th>
                        <td>
                            <select name="search-sort" id="">
                                <option value="">全部</option>
                                <option value="19">精品界面</option>
                                <option value="20">推荐界面</option>
                            </select>
                        </td>--%>
                        <th width="70">关键字:</th>
                        <td><input class="common-text" placeholder="关键字" name="keywords" value="${param.searchKey}"
                                   id="" type="text">
                        </td>
                        <td><input class="btn btn-primary btn2" name="sub" value="查询" type="submit"></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <div class="result-wrap">
        <form action="adminDoUserDel?cp=${page}" name="adminDoUserDel" id="deleteUserByBatch" method="post">
            <div class="result-title">
                <div class="result-list">
                    <a href="adminUserAdd.jsp"><i class="icon-font"></i>新增用户</a>
                    <a id="batchDel" href="javascript:delBatch('你确定要删除这些用户吗？','deleteUserByBatch')"><i
                            class="icon-font"></i>批量删除</a>
                    <%--<a id="updateOrd" href="javascript:void(0)"><i class="icon-font"></i>更新排序</a>--%>
                </div>
            </div>
            <div class="result-content">
                <table class="result-tab" width="100%">
                    <tr>
                        <th class="tc" width="5%"><input class="allChoose" onclick="selAll(this)" name=""
                                                         type="checkbox"></th>
                        <th>ID</th>
                        <th>姓名</th>
                        <th>性别</th>
                        <th>Email</th>
                        <th>手机</th>
                        <th>用户属性</th>
                        <th>操作</th>

                    </tr>

                    <c:forEach var="u" items="${userList}">
                        <tr>
                            <c:if test="${u.user_status == 1}">
                                <td class="tc"><input name="id[]" value="${u.user_id}" type="checkbox"></td>
                            </c:if>
                            <c:if test="${u.user_status == 0}">
                                <td></td>
                            </c:if>

                            <td>${u.user_id}</td>
                            <td>${u.user_name}</td>
                            <c:choose>
                                <c:when test="${u.user_sex == 'M'}">
                                    <td>男</td>
                                </c:when>
                                <c:when test="${u.user_sex == 'W'}">
                                    <td>女</td>
                                </c:when>
                            </c:choose>

                            <td>${u.user_email}</td>
                            <td>${u.user_phone}</td>

                            <c:choose>
                                <c:when test="${u.user_status == 1}">
                                    <td>用户</td>
                                </c:when>
                                <c:when test="${u.user_status == 0}">
                                    <td>管理员</td>
                                </c:when>
                            </c:choose>

                            <td>
                                <a class="link-update" href="adminToUserUpdate?id=${u.user_id}&page=${page}">修改</a>
                                    <%--                                使后台无法删除管理员用户--%>
                                <c:if test="${u.user_status == 1}">
                                    <a class="link-del"
                                       href="javascript:Delete('确认删除用户${u.user_id}吗？','/cloudJiang/manage/adminDoUserDel?id=${u.user_id}&page=${page}')">删除</a>
                                </c:if>
                            </td>
                        </tr>
                    </c:forEach>

                    <script>
                        // 弹出小窗确认删除用户
                        function Delete(msg, url) {
                            // 如果点击确认，则confirm为真
                            if (confirm(msg)) {
                                location.href = url;
                            }
                        }

                        function delBatch(msg, formName) {
                            if (confirm(msg)) {
                                const form = document.getElementById(formName);

                                form.submit();
                            }
                        }

                        /**
                         * 将a的checked属性与o的checked属性绑定，实现较为方便的全选
                         * 其中 o 是表头元素复选框
                         *     a 是表格元素复选框
                         * @param o
                         */
                        function selAll(o) {
                            const a = document.getElementsByName('id[]');

                            for (let i = 0; i < a.length; i++) {
                                a[i].checked = o.checked;
                            }
                        }
                    </script>

                </table>
                <div class="list-page">
                    共${numOfUser}条记录，当前在第${page}/${totalPage}页。

                    <a href="adminDoUserGet?cp=1${searchKey}">首页</a>
                    <a href="adminDoUserGet?cp=${page-1 < 1? 1:page-1}${searchKey}">上一页</a>
                    <a href="adminDoUserGet?cp=${page+1 > totalPage? totalPage:page+1}${searchKey}">下一页</a>
                    <a href="adminDoUserGet?cp=${totalPage}${searchKey}">尾页</a>

                </div>
            </div>
        </form>
    </div>
</div>
<!--/main-->
</div>
</body>
</html>